package com.atguigu.tingshu.order.mq;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
@Slf4j
public class OrderReceiver {

    @Autowired
    private OrderInfoService orderInfoService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void receivePayedOrderInfo(ConsumerRecord<String , String> consumerRecord)  {
        String value = consumerRecord.value();
        if(!StringUtils.isEmpty(value)) {
            orderInfoService.orderPaySuccess(value);        // 更改订单的支付状态，并且保存购买信息
            log.info("更改订单的支付状态以及保存购买信息成功了...orderNo: {} " , value);
        }
    }

}
